home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gwu / adaed / math / primfunc.ads < prev    next >
Encoding:
Text File  |  1996-01-30  |  3.1 KB  |  87 lines

  1. --  -----------------------------------------------------------------------
  2. --  Title:       primitive_functions
  3. --  Last Mod:    Thu Apr 19 11:24:34 1990
  4. --  Author:      Vincent Broman <broman@nosc.mil>
  5. --   Copyright 1990 Vincent Broman
  6. --     Permission granted to copy, modify, or compile this software for
  7. --   one's own use, provided that this copyright notice is preserved intact.
  8. --     Permission granted to distribute compiled binary copies of this
  9. --   software which are linked in with some other application.
  10. --     Permission granted to distribute other copies of this software,
  11. --   provided that (1) any copy which is not source code, i.e. not in the
  12. --   form in which the software is usually maintained, must be accompanied
  13. --   by a copy of the source code from which it was compiled, and (2) the
  14. --   one distributing it must refrain from imposing on the recipient
  15. --   further restrictions on the distribution of this software.
  16. --   
  17. --  Visibility:  
  18. --  Description: 
  19. --               functions on floating point types whose implementation
  20. --               does not depend on access to the mantissa/exponent 
  21. --               representation of the floating point number.  this includes
  22. --               integer/fraction operations.
  23. --               
  24. --  Exceptions:  numeric_error upon overflow,
  25. --               constraint_error only if type Float is constrained.
  26. --  -----------------------------------------------------------------------
  27. package primitive_functions is
  28. -- 
  29.    function exponent( x: Float) return integer;
  30. --
  31. -- return the exponent k such that 1/2 <= x/(2**k) < 1,
  32. -- or zero for x = 0.0 .
  33. -- 
  34.  
  35.    function mantissa (x: Float) return Float;
  36. --
  37. -- return scale( x, - exponent( x)) if x is nonzero,  0.0 otherwise.
  38. --
  39.  
  40.    function scale (x: Float;
  41.            k: integer) return Float;
  42. --
  43. -- return x * 2**k quickly, or quietly underflow to zero,
  44. -- or raise an exception on overflow.
  45. -- 
  46.  
  47.    function shorten (x: Float;
  48.              k: integer) return Float;
  49. -- 
  50. -- set all but the k most significant bits in the mantissa of x to zero,
  51. -- i.e. reduce the precision to k bits, truncating, not rounding.
  52. -- shorten( x, k) = 0.0 if k < 1 and
  53. -- shorten( x, k) = x   if k >= Float'machine_mantissa.
  54. -- 
  55.  
  56.    function odd (x: Float) return boolean;
  57. --
  58. -- predicate indicates whether or not truncate( x) is an odd integer.
  59. --
  60.  
  61.    function truncate (x: Float) return Float;
  62. --
  63. -- truncate x to the nearest integer value with absolute value
  64. -- not exceeding abs( x).  No conversion to an integer type
  65. -- is expected, so truncate cannot overflow for large arguments.
  66. --
  67.  
  68.    function floor (x: Float) return Float;
  69. --
  70. -- return as a Float the greatest integer value <= x.
  71. --
  72.  
  73.    function ceiling (x: Float) return Float;
  74. --
  75. -- return as a Float the least integer value >= x.
  76. --
  77.  
  78.    function round (x: Float) return Float;
  79. --
  80. -- return as a Float the integer value nearest x.
  81. -- in case of a tie, prefer the even value.
  82. --
  83.  
  84. end primitive_functions;
  85.  
  86. -- $Header: g_primitive_functions_s.ada,v 3.13 90/04/19 12:34:11 broman Rel $
  87.